package com.wzy;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.Date;

@SpringBootApplication
@MapperScan("com.wzy.mapper")
public class SpringbootMpApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootMpApplication.class, args);
    }
    @Bean
    public AuditTimeMetaObjectHandler auditTimeMetaObjectHandler() {
        return new AuditTimeMetaObjectHandler();
    }

    private static class AuditTimeMetaObjectHandler implements MetaObjectHandler {
        /**
         * 创建时间
         */
        @Override
        public void insertFill(MetaObject metaObject) {
            if (metaObject.hasGetter("createTime")) {
                setFieldValByName("createTime", new Date(), metaObject);
            }
        }

        /**
         * 最后一次更新时间
         */
        @Override
        public void updateFill(MetaObject metaObject) {
            if (metaObject.hasGetter("updateTime")) {
                setFieldValByName("updateTime", new Date(), metaObject);
            }
        }
    }


}
